<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> 
<head>
<%@ include file="../../include/easyui.jsp" %>
<%@ include file="../../include/pGrid.jsp" %>
<script type="text/javascript" src="/plug-in/jquery-easyui-1.5.1/datagrid-detailview.js"></script>
<title>订单管理</title>
<script>
	$(function(){
		p.isTab = true;
		var columns = [[
			{field: 'outContractNo', title: '内部合同编号', width: 130}
			,{field: 'contractNo', title: '订单编号', width: 270}
			,{field: 'contractName', title: '订单名称', width: 250}
			,{field: 'contractType', title: '订单类型', width: 80}
			,{field: 'contractLevel', title: '级别', width: 100}
			,{field: 'signYear', title: '年份', width: 60}
			,{field: 'signDate', title: '签订日期', width: 120}
			,{field: 'partA', title: '合同甲方', width: 250}
			,{field: 'partB', title: '合同乙方', width: 250}
			,{field: 'partAuser', title: '甲方经办人', width: 120}
			,{field: 'partAphone', title: '甲方联系电话', width: 120}
			,{field: 'partBuser', title: '乙方经办人', width: 120}
			,{field: 'partBphone', title: '乙方联系电话', width: 120}
			,{field: 'budgetMoney', title: '预算金额', width: 90}
			,{field: 'actualMoney', title: '实际金额', width: 90}
			,{field: 'billMoney', title: '开票金额', width: 90}
			,{field: 'auditMoney', title: '审计金额', width: 90}
			,{field: 'returnedMoney', title: '回款金额', width: 90}
			,{field: 'payDesc', title: '付款情况及说明', width: 130}
			,{field: 'mainUnit', title: '总包单位', width: 180}
			,{field: 'assistUnit', title: '分包单位', width: 180}
			,{field: 'orgNo', title: '所属机构', width: 180,formatter: function(value,row,index){
				return (value || '') + '-' + (row.orgNoName|| '') ;
			}}
			,{field : 'remark',width : 150,title: '备注'}
			,{field: 'createTime', title: '创建时间', width: 180}
			,{field: 'createrName', title: '创建人', width: 180}
		]] ;
		/*列表初始化*/
		var gridParam = {
			queryParams:{
				className: 'com.fs.jzzn.pojo.Contract',
				rightControl: true,//启用数据权限控制
				contractLevel: '子订单',
				contractLevel_searchType:'eq'
			},
			url : '/console/com.fs.jzzn.pojo.Contract/list',
			columns : columns,
			autoRowHeight: true,
			singleSelect : true,
			nowrap: true,
			onLoadSuccess: function(){
				p.tooltip(['contractNo' ,  'contractTitle' , 'outContractNo' , 'contractName' ,'partA' ,'partB' ,'partAuser' ,'payDesc' ]);
			},
			view: detailview,
			detailFormatter:function(index,row){
				return '<div style="padding:5px;min-height:50px;"><table id="details-' + index + '"></table></div>';
			},
			onExpandRow:function(index,row){
				var contractNo = row.contractNo || '';
				if(contractNo=='') return ;
				if(row.contractLevel=='框架协议'){
					var detailGrid = $('#details-' + index).datagrid({
						columns : columns,
	                    url: '/console/com.fs.jzzn.pojo.Contract/list',
	                    title:'框架协议子订单列表',
	                    queryParams: {
							contractNo: row.contractNo,
							contractNo_searchType: 'like',
							outContractNo: row.outContractNo,
							outContractNo_searchType: 'neq',
							contractLevel:'子订单',
							contractLevel_searchType: 'eq',
						},
	                    fitColumns: true,
	                    singleSelect: true,
	                    rownumbers: true,
	                    loadMsg: '加载中...',
	                    autoRowHeight: true,
	                    height: 'auto',
	                    sortName: 'contractNo',             //排序列名
	                    sortOrder: 'asc',
	                    onResize: function () {
	                    	 $('#dataGrid').datagrid('fixDetailRowHeight',index); 
	                   	},
	                    onLoadSuccess: function () {
	                    	setTimeout(function(){
	                            //在加载爷爷列表明细（即：父列表）成功时，获取此时整个列表的高度，使其适应变化后的高度，此时的索引
	                            $('#dataGrid').datagrid('fixDetailRowHeight',index);
	                            $('#dataGrid').datagrid('fixRowHeight',index);//防止出现滑动条
	                        },0);
	                    },
	                    toolbar: [
    				          { iconCls: 'icon-excel', text:'子订单合同导出',handler: function(){
    					        	  p.down({
    					        		  filename: row.contractTitle,local :true,grid: detailGrid,
    					        		  url:'/console/contract/export'
    					        	 });
    				          }}
    					],
    					view: detailview,
    					detailFormatter:function(indexc,rowc){
    						return '<div style="padding:5px;min-height:100px;"><table id="detailsc-' + indexc + '"></table></div>';
    					},
   					 onCollapseRow: function (indexc,rowc) {
	   						 setTimeout(function () {
		                 		 	$('#details-' + index).datagrid('fixDetailRowHeight',indexc);
		                 		 	$('#details'+index).datagrid('fixRowHeight',indexc);
		                             $('#dataGrid').datagrid('fixDetailRowHeight',index);
		                             $('#dataGrid').datagrid('fixRowHeight',index);
		                 	 }, 0);
   	                    },
    					onExpandRow:function(indexc,rowc){
    						var contractNoc = rowc.contractNo || '';
    						if(contractNoc=='') return ;
    						var detailcGridc = $('#detailsc-' + indexc).datagrid({
    							rownumbers: true,
    							title:'子订单或合同子单项工程列表',
    							singleSelect: true, 
    							fitColumns: true,
    		                    singleSelect: true,
    		                    rownumbers: true,
    		                    loadMsg: '加载中...',
    		                    autoRowHeight: true,
    		                    height: 'auto',
    							columns : [[
    								{field: 'pNo', title: '工程路段编号', width: 130} 
    								,{field: 'pRoad', title: '工程段落', width: 270}
    								,{field: 'status', title: '项目状态', width: 120}
    								,{field: 'pType', title: '专业类别', width: 80}
    								,{field: 'contractNo', title: '订单编号', width: 240}
    								,{field: 'pName', title: '项目名称', width: 250}
    								,{field: 'budgetMoney', title: '立项预算', width: 90}
    								,{field: 'actualMoney', title: '完工预算', width: 90}
    								,{field: 'designLength', title: '设计长度', width: 80}
    								,{field: 'pm', title: '项目经理', width: 100}
    								,{field: 'marketManager', title: '市场负责人', width: 100}
    								,{field: 'constructionUnit', title: '建设单位', width: 200}
    								,{field: 'designUnit', title: '设计单位', width: 120}
    								,{field: 'operator', title: '运营商', width: 120}
    								,{field: 'ppm', title: '工程经理', width: 120}
    								,{field: 'orgNo', title: '所属机构', width: 180,formatter: function(value,row,index){
    									return (value || '') + '-' + (row.orgNoName|| '') ;
    								}}
    								,{field: 'pCreateDate', title: '订单日期', width: 120}
    								,{field: 'subpackage', title: '是否分包', width: 120}
    								,{field: 'subpackageScale', title: '分包比例', width: 120}
    								,{field: 'region', title: '区域', width: 120}
    								,{field: 'priority', title: '优先级', width: 120}
    								,{field : 'remark',width : 150,title: '备注'}
    								,{field: 'createTime', title: '创建时间', width: 130}
    								,{field: 'createrName', title: '创建人', width: 120}
    							]],
    							url : '/console/com.fs.jzzn.pojo.Project/list',
    		                    queryParams: {
    		                    	contractNo: rowc.contractNo,
    								contractNo_searchType: 'eq'
    							},
    							toolbar: [
    						          { iconCls: 'icon-excel', text:'子单项工程导出',handler: function(){
    							        	  p.down({
    							        		  filename: rowc.contractTitle,local :true,grid: detailcGridc,
    							        		  url:'/console/project/export'
    							        	 });
    						          }}
    							],
    							onResize: function () {
    	                                $("#details-" + index).datagrid("fixDetailRowHeight", indexc);
    	                                $('#dataGrid').datagrid('fixDetailRowHeight', index);
    		                   	},
    		                    onLoadSuccess: function () {
    		                    	 setTimeout(function () {
    		                    		 	$('#details-' + index).datagrid('fixDetailRowHeight',indexc);
    		                    		 	$('#details'+index).datagrid('fixRowHeight',indexc);
    		                                $('#dataGrid').datagrid('fixDetailRowHeight',index);
    		                                $('#dataGrid').datagrid('fixRowHeight',index);
    		                    	 }, 0);
    		                    	 
    		                        var dData = detailcGridc.datagrid('getData');
    								var total = {budgetMoney:0,actualMoney:0,designLength: 0,pName:'合计：'};
    								$.each(dData.rows ||[], function (i,item) {
    									total.budgetMoney += parseFloat(item.budgetMoney || '0');
    									total.actualMoney += parseFloat(item.actualMoney || '0');
    									total.designLength += parseFloat(item.designLength || '0');
    								});
    								total.budgetMoney = total.budgetMoney.toFixed(2);
    								total.actualMoney = total.actualMoney.toFixed(2);
    								total.designLength = total.designLength.toFixed(2);
    								detailcGridc.datagrid('appendRow',total);
    		                    }
    						});
    						
    						$('#details'+index).datagrid('fixDetailRowHeight',indexc);
    						$('#details'+index).datagrid('fixRowHeight',indexc);
    	                    $('#dataGrid').datagrid('fixDetailRowHeight',index);
    	                    $('#dataGrid').datagrid('fixRowHeight',index);
    					}
				});
			}else{
				var detailGrid = $("#details-" + index).datagrid({
					url : '/console/com.fs.jzzn.pojo.Project/list',
					queryParams: {
						contractNo: row.contractNo,
						contractNo_searchType: 'eq'
					},
					title:'子单项工程列表-'+ row.contractNo,
					pageSize:30,
					rownumbers: true,
					pagination: true,
					singleSelect: true, 
					columns : [[
						{field: 'pNo', title: '工程路段编号', width: 130} 
						,{field: 'pRoad', title: '工程段落', width: 270}
						,{field: 'status', title: '项目状态', width: 120}
						,{field: 'pType', title: '专业类别', width: 80}
						,{field: 'contractNo', title: '订单编号', width: 240}
						,{field: 'pName', title: '项目名称', width: 250}
						,{field: 'budgetMoney', title: '立项预算', width: 90}
						,{field: 'actualMoney', title: '完工预算', width: 90}
						,{field: 'designLength', title: '设计长度', width: 80}
						,{field: 'pm', title: '项目经理', width: 100}
						,{field: 'marketManager', title: '市场负责人', width: 100}
						,{field: 'constructionUnit', title: '建设单位', width: 200}
						,{field: 'designUnit', title: '设计单位', width: 120}
						,{field: 'operator', title: '运营商', width: 120}
						,{field: 'ppm', title: '工程经理', width: 120}
						,{field: 'orgNo', title: '所属机构', width: 180,formatter: function(value,row,index){
							return (value || '') + '-' + (row.orgNoName|| '') ;
						}}
						,{field: 'pCreateDate', title: '订单日期', width: 120}
						,{field: 'subpackage', title: '是否分包', width: 120}
						,{field: 'subpackageScale', title: '分包比例', width: 120}
						,{field: 'region', title: '区域', width: 120}
						,{field: 'priority', title: '优先级', width: 120}
						,{field : 'remark',width : 150,title: '备注'}
						,{field: 'createTime', title: '创建时间', width: 130}
						,{field: 'createrName', title: '创建人', width: 120}
					]],
					 onResize: function () {
                    	 $('#dataGrid').datagrid('fixDetailRowHeight',index); 
                   	},
					onLoadSuccess:function(){
						setTimeout(function(){
                            $('#dataGrid').datagrid('fixDetailRowHeight',index);
                            $('#dataGrid').datagrid('fixRowHeight',index);//防止出现滑动条
                        },0);
						
						p.tooltip(['pRoad','contractNo','pName','remark']);
						var dData = detailGrid.datagrid('getData');
						var total = {budgetMoney:0,actualMoney:0,designLength: 0,pName:'合计：'};
						$.each(dData.rows ||[], function (i,item) {
							total.budgetMoney += parseFloat(item.budgetMoney || '0');
							total.actualMoney += parseFloat(item.actualMoney || '0');
							total.designLength += parseFloat(item.designLength || '0');
						});
						total.budgetMoney = total.budgetMoney.toFixed(2);
						total.actualMoney = total.actualMoney.toFixed(2);
						total.designLength = total.designLength.toFixed(2);
						detailGrid.datagrid('appendRow',total);
					},
					toolbar: [
				          { iconCls: 'icon-excel', text:'单项工程列表导出',handler: function(){
					        	  p.down({
					        		  filename: row.contractTitle,local :true,grid:detailGrid,
					        		  url:'/console/project/export'
					        	 });
				          }}
					]
				});
			}
		}
			/*,onExpandRow:function(index,row){
				
			}*/
	};
	p.dataGrid = $(p.dataGrid).datagrid( $.extend({}, p.dataGridParam, gridParam));

		/*事件响应*/
		$("#toolbar .easyui-linkbutton").on("click", function() {
			var id = $(this).attr("motion_code");p.btnOneClick($(this));
			switch (id) {
				case "01":
					p.gridAdd({ 
						title : "订单管理新增", width : 850, height : 430 ,autoMax:true,isTab:true
						,href:'/console/page?pageName=order/add'	
					});
					break;
				case "02":
					var row = p.getSelection("请选择一条记录进行编辑");
					if(row){
						p.gridModify({title : "订单管理编辑-"+ row.contractNo ,width : 850, height : 430,autoMax:true
							,href:'/console/page?pageName=order/modify'	
						});
					}
					break;
				case "03":
					p.gridDelete({url: '/console/contract/delete'});
					break;
				case "04":
					var row = p.getSelection("请选择一条记录进行编辑");
					if(row){
						p.gridView({title : "订单记录查看"+ row.contractNo, width : 850, height : 430,autoMax:true
							,href:'/console/page?pageName=order/view'		
						});				
					}
					break;
				case "05":
					p.gridQuery();
					break;
				case "07":
		            p.down({filename:'订单管理',url: '/console/contract/export'});
		         	break;
				case "10":
					var row = p.getSelection();
					if(row){
						p.gridOpt({ title : '订单信息更多'+ row.contractNo,data:row, width : 850, height : 430 ,data: row,href:'/console/contract/config',autoMax:true });
					}
					break;
				case "14"://复制
					var row = p.getSelection('请先选定一条记录再复制!');
					if(row){
						p.gridAdd({ title : '订单记录复制', width : 850, height : 430 ,autoMax:true
							,href:'/console/page?orderId='+ row.id +'&pageName=order/add'		
						});
					}
					break;
				case "19":
					p.gridAdd({href:'/console/contract/import', title : "订单数据导入", width : 550, height : 330 });
					break;
				default:
					break;
			}
		});
	});
</script>
</head>
<body  class="easyui-layout">
		<!-- 但行高度33px，多行时 33乘以行数  -->
		<div id="querybar" data-options="region:'north',split:false,border:false" style="height:auto;">
			<div class="easyui-panel" data-options="fit:true,border:false">
				<!-- 查询条件表单，根据配置进行替换  -->
				<form id="queryForm" >
				 <input type="hidden" name="className" value="com.fs.jzzn.pojo.Contract" />
				 <div style="margin-top:5px;margin-left:10px;float:left;">
				  	<input class="easyui-textbox" name="contractNo" style="width:240px;" data-options="label:'订单编号:',required:false,labelWidth:60,prompt:'订单编号关键词' " />
					<input type="hidden" name="contractNo_searchType" value="like" />
				 </div>
				 <div style="margin-top:5px;margin-left:10px;float:left;">
				  	<input class="easyui-textbox" name="contractName" style="width:240px;" data-options="label:'订单名称:',required:false,labelWidth:60,prompt:'订单名称关键词' " />
					<input type="hidden" name="contractName_searchType" value="like" />
				 </div>
				  <div style="margin-top:5px;margin-left:10px;float:left;">
				  	<select class="easyui-combobox" name="signDate" style="width:240px;" data-options="label:'年份:',required:false,labelWidth:60" >
				  		<option value="">==全部==</option>
				  		<option value="2018">2018</option>
				  		<option value="2017">2017</option>
				  		<option value="2016">2016</option>
				  		<option value="2015">2015</option>
				  		<option value="2014">2014</option>
				  		<option value="2013">2013</option>
				  		<option value="2012">2012</option>
				  		<option value="2011">2011</option>
				  	</select>
					<input type="hidden" name="signDate_searchType" value="like" />
				 </div>
				 
				 <div  style="margin-top:5px;margin-left:10px;float:left;">
				 	<input type="hidden" name="orgNo_searchType" value="like" />
				 	<select class="easyui-combotreegrid" id="orgNo_tree" name="orgNo" style="width:240px;" data-options="label:'组织结构:',panelWidth:300,labelWidth:60,
			           	prompt:'请选择组织机构',
			           	idField: 'orgNo', 
						treeField: 'orgName',
						sortName:'orgOrder',
						icons: [{
							iconCls:'icon-remove',
							handler: function(e){
								$(e.data.target).textbox('setValue', '');
							}
						}],
						iconAlign:'right',
						textField:'orgName',
						onSelect:function(row){
							$('#orgNo_tree').combogrid('setText', row.orgName);
						},
						sortOrder:'asc',
			            url:'/console/com.fs.base.pojo.Org/list', 
			            queryParams:{isTreeGrid:'true', treeId:'id', treePid:'parentId' },
			            columns:[[    
			                {field:'orgName',			width:250,	title:'组织名称' }
			            ]]"></select>
				 </div>
				 <div class="fItem">
			  		<input class="easyui-combobox" name="createrId" style="width:240px;" url="/console/combobox?valueField=id&textField=nickName&modleName=user" data-options="label:'创建人:',required:false,labelWidth:60" />
			  		<input type="hidden" name="createrId_searchType" value="eq" />
			 	</div>
			 	
			 	<div class="fItem">
				 	<input class="easyui-datebox" style="width:240px;" name="createTime" data-options="label:'开始日期:',required:false,labelWidth:60" />
				 	<input type="hidden" name="createTime_searchType" value="between" />
				 	<input type="hidden" name="createTime_format" value="date" />
				</div>
				<div class="fItem">
				 	<input class="easyui-datebox" style="width:240px;" name="createTime" data-options="label:'截至日期:',required:false,labelWidth:60" />
				</div>
				</form>
			</div>
		</div>  
	
		<!-- 工具栏按钮 -->
		<div id="toolbar" class="easyui-panel" style="padding:3px;"></div>
		
		<!-- 表格 -->
		<div region="center" border="false">
			<table id="dataGrid"></table>
		</div>
</body>
</html>